//
//  RecordDetailView.swift
//  Scaner
//
//  Created by liyahao on 2025/4/15.
//

import SwiftUI

enum Groups: CaseIterable {
    case metting, classRoom, none
    
    var title: String {
        switch self {
        case .metting:
            return "会议"
        case .classRoom:
            return "课堂"
        case .none:
            return "未分组"
        }
    }
}

struct RecordDetailView: View {
    var model: AudioFiles
    @State var group = Groups.metting
    
    var body: some View {
        VStack(spacing: 16, content: {
            HStack {
                VStack(alignment: .leading, spacing: 8) {
                    Text(model.name)
                        .font(.title3.weight(.medium))
                        .foregroundStyle(Color(.darkText))
                    
                    HStack {
                        Text(model.duration.formatTime)
                            .font(.system(size: 14))
                            .foregroundStyle(Color(.darkText))

                        Text(model.tsp.tspFormat() ?? "")
                            .font(.system(size: 14))
                            .foregroundStyle(Color(.systemGray))
                    }
                }
                Spacer()
                Picker("分组", selection: $group) {
                    ForEach(Groups.allCases, id: \.self) { group in
                        Text(group.title)
                            .font(.system(size: 14))
                            .foregroundStyle(Color(.systemGray))
                    }
                }
                .foregroundStyle(Color(.systemGray))
            }
            
            Divider()
            
            ScrollView {
                VStack {
                    if let asr = model.asr {
                        Text(asr)
                            .font(.system(size: 17))
                            .foregroundStyle(Color(.darkText))
                            .lineSpacing(3)
                            .multilineTextAlignment(.leading)
                            .frame(maxWidth: .infinity, alignment: .leading)
                            .padding()
                    }
                }
                .background {
                    RoundedRectangle(cornerRadius: 16)
                        .fill(Color.black.opacity(0.3))
                }
            }
            PlayCtrlView()
        })
        .padding(.horizontal)
        
        .navigationBarTitleDisplayMode(.inline)
        .navigationTitle("我的录音")
        .toolbar {
            ToolbarItem(placement: .topBarTrailing) {
                Button {
                    
                } label: {
                    Image(systemName: "trash")
                        .font(.system(size: 14))
                        .foregroundStyle(Color(.darkText))
                }
            }
        }
    }
}

#Preview {
    NavigationView {
        RecordDetailView(model: AudioFiles.samples.first!)
    }
}
